package cn.com.v2.controller;

import cn.com.v2.common.domain.AjaxResult;
import cn.com.v2.util.QiNiuUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.UnsupportedEncodingException;

import static cn.com.v2.common.domain.AjaxResult.success;

/**
 * 文件服务控制层
 */
@RestController
@RequestMapping("/qiniu/file")
@Slf4j
public class QiniuFileController {

    /**
     * 文件上传
     *
     * @param multipartFile 文件
     * @return 文件名
     */
    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam("file") MultipartFile multipartFile) throws UnsupportedEncodingException {
        String filename = QiNiuUtil.uploadMultipartFile(multipartFile, null);
        log.info("文件上传成功，文件名为：{}", filename);
        return success(filename);
    }

}
